import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import('../views/home/index.vue'),
    meta: {
      title: "首页"
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue'),
    meta: {
      title: "登录"
    }
  },
  {
    path: '/rotate',
    name: 'rotate',
    component: () => import('../views/home/rotate.vue'),
    meta: {
      title: "3D旋转"
    }
  },
]

const router = createRouter({
  // history: 引入 createWebHistory hash: 引入 createWebHashHistory 
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

//导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// 不重定向白名单
// const whiteList = ['login', 'forget', 'register']
// router.beforeEach((to, from, next) => {
   //设置每页title
  //  if (to.meta.title) {
  //   document.title = to.meta.title
  // }
	// if (whiteList.indexOf(to.name) !== -1) {
	// 	next();
	// } else {
	// 	if (localStorage.getItem('token')) {
	// 		next()
	// 	} else {
	// 		//errorShow('token失效，请重新登录')
	// 		next(`/login`) // 否则全部重定向到登录页
	// 	}
	// }
// });

export default router
